<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/thesame.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/page.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/rightCon.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/css/popCss.css}" media="all">
</head>

<body class="layui-layout-body layui-layout-body-scroll">
<div class="layui-body">
    <!-- 内容主体区域 -->
    <div class="scroll-box bgWhite box-shadows border-radius4">
        <div class="scroll-box-padding">
            <div class="scroll-box-con">
                <div class="border-bot1px pb10px mb20px">
                    <div class="form-box form-box-access form-style">
                        <div>
                            <div class="form-title">
                                <label>关键字：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <input type="text" id="userName" placeholder="请输入姓名" maxlength="20">
                                </p>
                            </div>
                        </div>
                        <div>
                            <div class="form-title">
                                <label>部门：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <select class="form-select-img" id="deptName">

                                    </select>
                                </p>
                            </div>
                        </div>
                        <div>
                            <div class="form-title">
                                <label>人员类别：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <select class="form-select-img" id="userType">
                                        <option value="">请选择</option>
                                        <option value="1">员工</option>
                                        <option value="2">访客</option>
                                    </select>
                                </p>
                            </div>
                        </div>
                        <div>
                            <div class="form-title">
                                <label>设备名称：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <select class="form-select-img" id="deviceName">

                                    </select>
                                </p>
                            </div>
                        </div>
                        <div style="width: 50%;">
                            <div class="form-title">
                                <label>记录时间：</label>
                            </div>
                            <div class="form-content">
                                <p>
                                    <input id="startTime" readonly type="text" placeholder="请选择" class="form-input-time test-item">
                                </p>
                            </div>
                        </div>
                        <div class="form-box-btn overflow" style="width: 16%;">
                            <span id="serchBtn" class="white border-radius4 border-blue blue inline-block pl20px pr20px lh30px cursor">查&nbsp;询</span>
                        </div>
                    </div>
                </div>
                <div>
                    <div class="mb20px lh32px overflow table-btn-img">
                        <!--                        <p class="left">-->
                        <!--                            <span class="white border-radius4 bgBlue-linear inline-block pl15px pr15px cursor"><img src="img/icon_add.png">新建</span>-->
                        <!--                        </p>-->
                        <p class="right">共<span class="red" id="count"></span>条数据</p>
                    </div>
                    <div class="border1px border-box border-radius4 layui-table-img">
                        <table class="layui-hide" id="test" lay-filter="test"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script th:src="@{/static/js/jquery-3.1.1.min.js}"></script>
<script th:src="@{/static/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/static/js/selectColor.js}" charset="utf-8"></script>
<script>

    $(function () {
        getData();

        $("#serchBtn").click(function () {
            getData();
        });

        //    加载设备名
        loadDevice();
        //    加载部门名
        loadDept();
    });

    function loadDevice() {
        $.ajax({
            url: "../device/getDeviceListAll",
            type: "get",
            async: false,
            dataType: "json",
            success: function (data) {
                var str = "<option value=\"\">请选择</option>";
                if (data.code == 0) {
                    if (data.data.length > 0) {
                        for (var i = 0; i < data.data.length; i++) {
                            str += "<option value=" + data.data[i].id + ">" + data.data[i].deviceName + "</option>"
                        }
                    }
                }
                $("#deviceName").html(str);
            }
        })
    }

    function loadDept() {
        $.ajax({
            url: "../userDept/getDeptByUser",
            type: "get",
            async: false,
            dataType: "json",
            success: function (data) {
                var str = "<option value=\"\">请选择</option>";
                if (data.code == 200) {
                    if (data.data.length > 0) {
                        for (var i = 0; i < data.data.length; i++) {
                            str += "<option value=" + data.data[i].id + ">" + data.data[i].deptName + "</option>"
                        }
                    }
                }
                $("#deptName").html(str);
            }
        })
    }


    function getData() {
        //左侧菜单栏
        layui.use(['element', 'table', 'laydate'], function () {
            var element = layui.element;
            var table = layui.table;
            var laydate = layui.laydate;
            //查询条件
            var userName = $("#userName").val();
            var deptName = $("#deptName").val();
            var userType = $("#userType").val();
            var deviceName = $("#deviceName").val();
            var startTime = $("#startTime").val();
            console.log(startTime);
            laydate.render({
                elem: '.test-item'
                , type: 'datetime'
                , range: '-'
                , format: 'yyyy-MM-dd HH:mm:ss'
            });


            //第一个实例
            table.render({
                elem: '#test'
                ,
                url: "../record/getRecordList"
                , where: {
                    userName: userName, deptName: deptName, userType: userType, deviceName: deviceName, startTime: startTime
                },
                id: 'idTest'
                , request: {
                    pageName: 'currentPage' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                },
                page: true //开启分页
                , limit: 10 //每页显示的条数
                //,limits:[3,4,5]
                , groups: 9 //连续页码个数
                , parseData: function (res) {
                    console.log(res);
                    return {
                        "code": res.code,
                        "data": res.data.list,
                        "count": res.data.total,
                        "limit": res.data.pageSize,
                    };
                },
                cols: [
                    [ //表头
                        {
                            title: '序号',
                            fixed: 'left',
                            type: 'numbers',
                            width: 70,
                        }, {
                        field: 'deptName',
                        title: '部门',
                    }, {
                        field: 'userType',
                        title: '类别',
                    }, {
                        field: 'userName',
                        title: '姓名',
                    }, {
                        field: 'userSex',
                        title: '性别',
                    }, {
                        field: 'mobile',
                        title: '手机号',
                    }, , {
                        field: 'userPhoto',
                        title: '照片',
                        templet: function (res) {
                            console.log(res);
                            return "<div class='table-img'><span><img src=" + res.userPhoto + "></span></div>"
                        }
                    }, {
                        field: 'deviceName',
                        title: '设备名称',
                    }, {
                        field: 'createTime',
                        title: '时间',
                    }
                    ]
                ], done: function (res, curr, count) {
                    $("#count").text(count);
                }
            });
        });
    }

</script>
</body>

</html>
